import numpy as np
from sklearn.manifold import TSNE,MDS
from sklearn import decomposition
from sklearn import preprocessing
import json
import os

jsonpath = "f:\\vscode-projects\\pubg2database\\test\\210305-gaoshoudata.json"
with open(jsonpath) as load_f:
    load_dict = json.load(load_f)
    # load_dict_gaoshou = list(filter(lambda x:x['is_gaoshou'],load_dict))
    array = []
    for i in load_dict:
        # print(i)
        array.append([i['distance_to_city_type_a'],
                      i['distance_to_city_type_b'],
                      i['distance_to_city_type_c'],
                      i['distance_to_city_type_d'],
                      i['distance_to_others'],
                      i['distance_to_airline'],
                      i['safetyzone_value']])
    #
    ""
    X = np.array(array)
    scaler = preprocessing.MinMaxScaler().fit(X)
    # scaler.min_
    # scaler.data_max_
    X_scaled = scaler.transform(X)
    tsne = TSNE(n_components=2, random_state=0)
    tsne.fit_transform(X_scaled)
    # mds = MDS(n_components=2, max_iter=3);
    # mds.fit_transform(X_scaled)
    # pca = decomposition.PCA(n_components=2);
    # pcaed = pca.fit_transform(X_scaled)
    with open("f:\\vscode-projects\\pubg2database\\test\\210307-gaoshou-tsne.json", "w") as save_f:
        json.dump(tsne.embedding_.tolist(), save_f)
        # json.dump(pcaed.tolist(), save_f)

    # print(tsne.embedding_)
# print(load_dict)
# DATA2 = json.load(jsonpath)
# X = np.array([[891.0, 0.1, 0.2], [0.1, 1.0, 0.3], [0.2, 0.1, 1.0], [0.5, 0.5, 0.5], [0.9, 0.8, 0.1]])

# '''输出
# [[   3.17274952 -186.43092346]
#  [  43.70787048 -283.6920166 ]
#  [ 100.43157196 -145.89025879]
#  [ 140.96669006 -243.15138245]]'
